package com.xiguaji.tiktok.task.core;

import java.util.ArrayList;
import java.util.List;

public class BloggerScore {
    private static List<Tuple> FansList = new ArrayList<>();
    private static List<Tuple> LikeList = new ArrayList<>();
    private static List<Tuple> CommentList = new ArrayList<>();
    private static List<Tuple> ShareList = new ArrayList();

    private static List<Tuple> FansInc = new ArrayList();
    private static List<Tuple> LikeInc = new ArrayList();
    private static List<Tuple> XiShu = new ArrayList();

    static{

        FansList.add(new Tuple(0.0,0.0));
        FansList.add(new Tuple(100000.0,30.0));
        FansList.add(new Tuple(300000.0,60.0));
        FansList.add(new Tuple(500000.0,70.0));
        FansList.add(new Tuple(1000000.0,80.0));
        FansList.add(new Tuple(5000000.0,90.0));
        FansList.add(new Tuple(10000000.0,98.0));
        FansList.add(new Tuple(100000000.0,200.0));

        LikeList.add(new Tuple(0.0,0.0));
        LikeList.add(new Tuple(5000.0,20.0));
        LikeList.add(new Tuple(10000.0,30.0));
        LikeList.add(new Tuple(100000.0,60.0));
        LikeList.add(new Tuple(200000.0,80.0));
        LikeList.add(new Tuple(500000.0,90.0));
        LikeList.add(new Tuple(1000000.0,95.0));
        LikeList.add(new Tuple(2000000.0,98.0));
        LikeList.add(new Tuple(3000000.0,99.0));

        CommentList.add(new Tuple(0.0,0.0));
        CommentList.add(new Tuple(100.0,10.0));
        CommentList.add(new Tuple(5000.0,90.0));
        CommentList.add(new Tuple(10000.0,95.0));

        ShareList.add(new Tuple(0.0,0.0));
        ShareList.add(new Tuple(1000.0,70.0));
        ShareList.add(new Tuple(10000.0,90.0));

        LikeInc.add(new Tuple(0.0,0.0));
        LikeInc.add(new Tuple(50000.0,100.0));
        LikeInc.add(new Tuple(1000000.0,200.0));
        LikeInc.add(new Tuple(10000000.0,500.0));

        XiShu.add(new Tuple(0.0,4.0));
        XiShu.add(new Tuple(10000.0,3.0));
        XiShu.add(new Tuple(1000000.0,1.0));
        XiShu.add(new Tuple(10000000.0,0.5));
        XiShu.add(new Tuple(1000000000.0,0.1));
        XiShu.add(new Tuple(10000000000.0,0.01));
    }

    private static Double GetScore(List<Tuple> list, Double v)
    {
        int i = 0;
        for (i = 0; i < list.size(); i++)
        {
            if (list.get(i).getItem1() > v){
                break;
            }
        }
        if (i == 0) {
            return 0.0;
        }
        if (i < list.size())
        {
            var s0 = list.get(i - 1).getItem2();
            var s1 = list.get(i).getItem2();
            var f0 = list.get(i - 1).getItem1();
            var f1 = list.get(i).getItem1();
            var per = (s1 - s0) / (f1 - f0);
            var s = s0 + (v - f0) * per;
            return s;
        }
        var rs = list.get(i - 1).getItem2() + (100 - list.get(i - 1).getItem2()) * (1 - 1 / ((v - list.get(i - 1).getItem1()) / (list.get(i - 1).getItem1() / 10) + 1));

        return rs;
    }

    public static Double GetTotalScore(ScoreParms parms)
    {
        parms.fansscore = 5 * GetScore(FansList, (double)parms.fans);
        parms.total = parms.fansscore;
        if (parms.artnumbers <= 0)
        {
            return parms.total + 200;
        }
        /*parms.like /= 1.0 * parms.artnumbers;
        parms.comment /= 1.0 * parms.artnumbers;
        parms.share /= 1.0 * parms.artnumbers;*/

        parms.likescore = 3 * GetScore(LikeList, parms.like);
        parms.commentscore = 1.5 * GetScore(CommentList, parms.comment);
        parms.sharescore = 0.5 * GetScore(ShareList, parms.share);
        parms.total += parms.likescore
                + parms.commentscore
                + parms.sharescore;


        return parms.total + 200;
    }

    public static Double GetIncScore(IncScoreParms tj)
    {
        tj.fanxishu = GetScore(XiShu, (double)tj.fan);
        //tj.likexishu = GetScore(XiShu, tj.like);
        tj.fanincscore = GetScore(FansInc, (double)tj.faninc) * tj.fanxishu * 0.6;
        tj.likeincscore = GetScore(LikeInc, (double)tj.likeinc) * tj.fanxishu * 0.4;
        tj.total = tj.fanincscore + tj.likeincscore;
        return tj.total;
    }

    public static class ScoreParms
    {
        public int fans;
        public Double like ;
        public Double comment ;
        public Double share ;
        public Double fansscore ;
        public Double likescore ;
        public Double commentscore ;
        public Double sharescore ;
        public int artnumbers ;
        public Double total ;
    }

    public class IncScoreParms
    {
        public int fan ;
        public int faninc ;
        public Double fanxishu ;
        public Double fanincscore ;
        public int like ;
        public int likeinc ;
        //public Double likexishu ;
        public Double likeincscore ;
        public Double total ;
    }

    public static class Tuple{

        private double item1;
        private double item2;

        public Tuple(Double item1,Double item2){
            this.item1 = item1;
            this.item2 = item2;
        }

        public double getItem1() {
            return item1;
        }

        public void setItem1(double item1) {
            this.item1 = item1;
        }

        public double getItem2() {
            return item2;
        }

        public void setItem2(double item2) {
            this.item2 = item2;
        }
    }

    public static void main(String[] args) {
        /*BloggerScore.ScoreParms scoreParms = new BloggerScore.ScoreParms();
        scoreParms.fans = 20000000;
        scoreParms.artnumbers = 121;
        scoreParms.comment = (double)8906;
        scoreParms.share = (double)8346;
        scoreParms.like = (double)731570;
        System.out.println(BloggerScore.GetTotalScore(scoreParms));*/

        BloggerScore.ScoreParms scoreParms = new BloggerScore.ScoreParms();
        scoreParms.fans = 17200000;
        scoreParms.artnumbers = 2;
        scoreParms.comment = (double)5000;
        scoreParms.share = (double)9700 ;
        scoreParms.like = (double)922000;
        System.out.println(BloggerScore.GetTotalScore(scoreParms));
    }
}
